package com.hqyj.springcloud.handler;

import com.hqyj.springcloud.pojo.Order;
import com.hqyj.springcloud.pojo.RestfulEntity;
import com.hqyj.springcloud.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderHandler {
    @Autowired
    private OrderService orderService;

    @PostMapping(value = "app02")
    public @ResponseBody RestfulEntity appendOrder(@RequestBody Order order){
        RestfulEntity entity = orderService.add(order);
        RestfulEntity restfulEntity = new RestfulEntity();
        restfulEntity.setCode(700);
        restfulEntity.setMessage("购买商品失败！");
        if (entity != null) {
            if (entity.getCode() == 200) {
                restfulEntity.setCode(200);
                restfulEntity.setMessage("购买商品成功！" + entity.getMessage());
            }
        }
        return restfulEntity;
    }
}
